package center.wxp.sentinel.controller;

import center.wxp.sentinel.feign.ProviderOneServiceFeign;
import center.wxp.sentinel.feign.ProviderServiceFeign;
import center.wxp.sentinel.service.ProviderService;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@RestController
@RefreshScope
public class ProviderController {
    @Resource
    private ProviderServiceFeign providerFeign;
    @Resource
    private ProviderOneServiceFeign providerOneServiceFeign;
    @Autowired
    private ProviderService providerService;
    //@Value("${name}")
    private String name;   //从nacos的配置中心获取值

    @GetMapping("/hi")
    @SentinelResource(value = "hi", blockHandler = "blockHandlerForGetUser", blockHandlerClass = ProviderController.class)
    public String hi(@RequestParam(value = "name", defaultValue = "forezp", required = false) String name) {
        String result = providerFeign.hi(name);
        return "hihihhhhh " + name;
    }


    @GetMapping(value = "/getUserById")
    public String getUserById(String name) {
        providerService.helloAnother(name);
        return "成功";
    }

    @GetMapping("/doSomeThing")
    public void doSomeThing(String name) {
       providerService.doSomeThing(name);
    }

    @GetMapping("/test")
    public String test() {
        providerService.test();
        return "成功";
    }


    @GetMapping("/config")
    public String config() {
        System.out.println(name);
        return "hello " + name;
    }

    @PostConstruct
    public void init(){
    }
}
